package com.example.rabbitmqspringboot.controller;

import com.example.rabbitmqspringboot.config.ConfirmConfig;
import com.example.rabbitmqspringboot.config.MyCallBack;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zfj
 * @date 2022/4/26 -16:55
 */
@RestController
@Slf4j
@RequestMapping("/confirm")
public class Producer {
	@Autowired
	private RabbitTemplate rabbitTemplate;

	@Autowired
	private MyCallBack myCallBack;

	String routingKey="key1";


	//发消息
	@GetMapping("/sendMessage/{message}")
	public void sendMessage(@PathVariable String message){
		CorrelationData correlationData=new CorrelationData("1");
		rabbitTemplate.convertAndSend(ConfirmConfig.CONFIRM_EXCHANGE_NAME,
				routingKey,message,correlationData);
		log.info("发送消息内容:{}",message);
		CorrelationData correlationData2=new CorrelationData("2");
		rabbitTemplate.convertAndSend(ConfirmConfig.CONFIRM_EXCHANGE_NAME,
				routingKey+"2",message,correlationData2);
		log.info("发送消息内容:{}",message);
	}
}
